/****************************************************************************

	COPYRIGHT(C) MAXSI SOFTWARE, JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010

    This file is part of Maxsi Installer.

    Maxsi Installer is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Maxsi Installer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Maxsi Installer.  If not, see <http://www.gnu.org/licenses/>.

	*/ #include "MaxsiInstallerContributors.h" /*

	If you modify this file, please enter your name below and provide contact
	information in MaxsiInstallerContributors.h. For more information please see
	MaxsiInstallerContributors.h.
	
	Contributors to this file:

	- Jonas 'Sortie' Termansen
	- [your name here]

	MaxsiInstaller.exe
	The main installing technology utilized in the powerful Maxsi Distribution
	platform.

	PageAgreementMaxsiDistributionNotice.cpp
	The first page shown when installing

****************************************************************************/

#include "MaxsiEngine.h"
#include "MaxsiDistributionLink.h"
#include "Main.h" 
#include "UI.h" 
#include "Thread.h"
#include "Data.h"


bool PageAgreementMaxsiDistributionNotice::InitializeForm(ME_Window* Parent)
{
	BaseClass::InitializeForm(Parent);

	RECT ClientSpace;
	GetClientRect (WindowHWND, &ClientSpace);

	char*		TextSTR		=	BuildString(6,
	ProductName,
	" uses the powerful Open-Source Maxsi Distribution Digital Distribution Platform. Statistics regarding your gameplay experience will be uploaded to the Master Servers when you play ", ProductName, ".\n\n"
	"Maxsi Distribution uses your Steam Account Name to identify your personal stats. Maxsi Software will never share your Steam Account Name with a third party. Your Steam Account Name cannot be used for anything else than anonymously identifying you.\n\n",
	ProductName, " features automatic updates and is automatically updated upon launch if you have an Internet Connection. For more information, please see:\nhttp://www.maxsi.dk/distribution/");

	Previous	=	CreateButton(WindowHWND,_MESTR("Previous"),0,0,0,0);
	Next		=	CreateButton(WindowHWND,_MESTR("Next"),0,0,0,0);
	Text		=	CreateLabelA(WindowHWND,TextSTR,0,0,0,0);

	delete[]	TextSTR;

	NewResolution((WORD)ClientSpace.right,(WORD)ClientSpace.bottom);

	return true;
}

bool PageAgreementMaxsiDistributionNotice::RenderForm(HWND hWnd)
{
	return	BaseClass::RenderForm(hWnd);
}

LRESULT PageAgreementMaxsiDistributionNotice::WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if (!Initialized) { return 0; }

	if ( message == WM_COMMAND )
	{
        switch(LOWORD(wParam)) 
        {
            case BN_CLICKED:
			{
				HWND ClickedButton = (HWND)lParam;
				if (ClickedButton == Previous)
				{
					ReplaceSelfWith( new PageWelcome );
				}
				else
				{
					ReplaceSelfWith( new PageAgreementMaxsiDistribution );
				}
			}				
            break;
			default:
			{
				return BaseClass::WindowProc(hWnd,message,wParam,lParam);
			}
		}
	}
	else
	{
		return BaseClass::WindowProc(hWnd,message,wParam,lParam);
	}
    return (0);

}


bool PageAgreementMaxsiDistributionNotice::TerminateForm()
{
	// Avoid calling this function twice, or worse,
	// if one of the functions called here invokes another
	// windows message that eventually leads to this point of code again.
	if (!Initialized) { return false; }
	Initialized	=	false;

	DestroyWindow(Previous);
	DestroyWindow(Next);
	DestroyWindow(Text);

	// If we are here, we are safe. Call the parent and ask him to continue our work.
	// Make sure he sets Initialized to false afterwards.
	Initialized	=	true;
	BaseClass::TerminateForm();
	return true;
}

bool PageAgreementMaxsiDistributionNotice::NewResolution( WORD Width, WORD Height)
{
	BaseClass::NewResolution(Width,Height);

	MoveWindow(Text,25,60,Width-25-25,Height-60-75,TRUE);
	MoveWindow(Previous,Width-2*125,Height-2*24,100,24,TRUE);
	MoveWindow(Next,Width-1*125,Height-2*24,100,24,TRUE);

	return true;
}